package com.taxinfo.view.dataImport;

import com.taxinfo.pojo.dto.AccBalMapInfoDto;
import com.taxinfo.service.AccBalMapInfoService;
import com.taxinfo.utils.SpringUtil;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;

import java.math.BigDecimal;
import java.util.List;


/**
 * @author wanghy
 * @version 1.0
 */
public class AccBalMapInfoTable extends TableView<AccBalMapInfoDto> {
    private String id;
    private final AccBalMapInfoService accBalMapInfoService = (AccBalMapInfoService) SpringUtil.getBean("AccBalMapInfoServiceImpl");

    private final ObservableList<AccBalMapInfoDto> items = FXCollections.observableArrayList();

    private final TableColumn<AccBalMapInfoDto, String> compSubNo = new TableColumn<>("企业科目编码");
    private final TableColumn<AccBalMapInfoDto, String> compSubName = new TableColumn<>("企业科目名称");
    private final TableColumn<AccBalMapInfoDto, String> subNo = new TableColumn<>("标准科目编码");
    private final TableColumn<AccBalMapInfoDto, String> subName = new TableColumn<>("标准科目名称");
    private final TableColumn<AccBalMapInfoDto, String>  subType = new TableColumn<>("标准科目类型");
    private final TableColumn<AccBalMapInfoDto, String> taxDecNo = new TableColumn<>("税务申报科目编码");
    private final TableColumn<AccBalMapInfoDto, String> taxSubName = new TableColumn<>("税务申报科目名称");
    private final TableColumn<AccBalMapInfoDto, BigDecimal> openBal = new TableColumn<>("期初余额");
    private final TableColumn<AccBalMapInfoDto, String> openType = new TableColumn<>("期初余额-方向");
    private final TableColumn<AccBalMapInfoDto, BigDecimal> currentDebit = new TableColumn<>("本期借方");
    private final TableColumn<AccBalMapInfoDto, BigDecimal> currentCredit = new TableColumn<>("本期贷方");
    private final TableColumn<AccBalMapInfoDto, String> endType = new TableColumn<>("期末余额-方向");
    private final TableColumn<AccBalMapInfoDto, BigDecimal> endBal = new TableColumn<>("期末余额");

    public AccBalMapInfoTable(String id) {
        setItems(items);
        initColumns();
        showAllData(id);

    }

    private void initColumns() {

        compSubNo.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCompSubNo()));
        compSubNo.setPrefWidth(100);
        compSubName.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCompSubName()));
        compSubName.setPrefWidth(300);
        subNo.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getSubNo()));
        subNo.setPrefWidth(100);
        subName.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getSubName()));
        subName.setPrefWidth(300);
        subType.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getSubType()));
        subType.setPrefWidth(100);
//        taxDecNo.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getTaxDecNo()));
//        taxDecNo.setPrefWidth(100);
//        taxSubName.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getTaxSubName()));
//        taxSubName.setPrefWidth(300);
        openBal.setCellValueFactory(param -> new SimpleObjectProperty(param.getValue().getOpenBal()));
        openBal.setPrefWidth(100);
        openType.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getOpenType()));
        openType.setPrefWidth(100);
        currentDebit.setCellValueFactory(param -> new SimpleObjectProperty(param.getValue().getCurrentDebit()));
        currentDebit.setPrefWidth(100);
        currentCredit.setCellValueFactory(param -> new SimpleObjectProperty(param.getValue().getCurrentCredit()));
        currentCredit.setPrefWidth(100);
        endType.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getEndType()));
        endType.setPrefWidth(100);
        endBal.setCellValueFactory(param -> new SimpleObjectProperty(param.getValue().getEndBal()));
        endBal.setPrefWidth(100);

        ObservableList<TableColumn<AccBalMapInfoDto, ?>> cols = getColumns();
        cols.add(compSubNo);
        cols.add(compSubName);
        cols.add(subNo);
        cols.add(subName);
        cols.add(subType);
//        cols.add(taxDecNo);
//        cols.add(taxSubName);
        cols.add(openType);
        cols.add(openBal);
        cols.add(currentDebit);
        cols.add(currentCredit);
        cols.add(endType);
        cols.add(endBal);
    }

    public void showAllData(String id) {
        items.clear();
        List<AccBalMapInfoDto> vos = accBalMapInfoService.selectAllData(id);
        if (vos == null){
            return;
        }
        items.addAll(vos);
    }

}
